package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(100)"`
	Password string `gorm:"type:varchar(100)"`
}

func (u *User) UserLogin(db *gorm.DB, username string) error {
	return db.Debug().Where("username=?", username).FirstOrCreate(u).Error
}

func (u *User) UserCreate(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UserUpdate(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Where("id=?", id).First(u).Error
}

func (u *User) FindUserByWechCode(db *gorm.DB, username string) error {
	return db.Where("username=?", u).Find(u).Error
}
